package com.andaily.infrastructure.mail.mailgun;

import com.andaily.infrastructure.mail.AndailyMailSender;
import com.andaily.infrastructure.support.LogHelper;

import java.util.Arrays;

/**
 * Use MailGun send mail in here.
 *
 * @author Shengzhao Li
 */
public class MailgunAndailyMailSender implements AndailyMailSender {

    /**
     * Logger
     */
    private static LogHelper log = LogHelper.create(MailgunAndailyMailSender.class);

    /**
     * Is or not use new thread send mail.
     */
    public static final boolean SEND_MAIL_USE_THREAD = false;

    private boolean sendMailUseThread = SEND_MAIL_USE_THREAD;

    public MailgunAndailyMailSender() {
        log.info("Initialize Mailgun Sender");
    }

    @Override
    public boolean sendSimpleMail(String subject, String content, String... to) {
        log.debug("Call sendSimpleMail [subject= " + subject + ", content= " + content + ", to= " + Arrays.toString(to) + "]");
        MailgunSendMailHandler sendMailHandler = new MailgunSendMailHandler(subject, content, to);
        return sendMailHandler.handle(sendMailUseThread);
    }

    public void setSendMailUseThread(boolean sendMailUseThread) {
        this.sendMailUseThread = sendMailUseThread;
    }
}
